package com.ocean.productDict.service.impl;

import java.util.*;

import com.ocean.common.core.domain.entity.SysUser;
import com.ocean.common.utils.ShiroUtils;
import com.ocean.common.utils.uuid.IdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ocean.productDict.mapper.OOceanAreaMapper;
import com.ocean.productDict.domain.OOceanArea;
import com.ocean.productDict.service.IOOceanAreaService;
import com.ocean.common.core.text.Convert;

/**
 * 海区维护Service业务层处理
 *
 * @author ocean
 * @date 2023-01-03
 */
@Service
public class OOceanAreaServiceImpl implements IOOceanAreaService
{
    @Autowired
    private OOceanAreaMapper oOceanAreaMapper;

    /**
     * 查询海区维护
     *
     * @param id 海区维护主键
     * @return 海区维护
     */
    @Override
    public OOceanArea selectOOceanAreaById(String id)
    {
        return oOceanAreaMapper.selectOOceanAreaById(id);
    }

    /**
     * 查询海区维护列表
     *
     * @param oOceanArea 海区维护
     * @return 海区维护
     */
    @Override
    public List<OOceanArea> selectOOceanAreaList(OOceanArea oOceanArea)
    {
        return oOceanAreaMapper.selectOOceanAreaList(oOceanArea);
    }

    /**
     * 新增海区维护
     *
     * @param oOceanArea 海区维护
     * @return 结果
     */
    @Override
    public int insertOOceanArea(OOceanArea oOceanArea)
    {
        SysUser sysUser = ShiroUtils.getSysUser();
        oOceanArea.setId(IdUtils.simpleUUID());
        oOceanArea.setCreateName(sysUser.getUserName());
        oOceanArea.setCreateBy(sysUser.getLoginName());
        oOceanArea.setCreateDate(new Date());
        oOceanArea.setUpdateName(sysUser.getUserName());
        oOceanArea.setUpdateBy(sysUser.getLoginName());
        oOceanArea.setUpdateDate(new Date());
        oOceanArea.setDepartId(sysUser.getDeptId().toString());
        return oOceanAreaMapper.insertOOceanArea(oOceanArea);
    }

    /**
     * 修改海区维护
     *
     * @param oOceanArea 海区维护
     * @return 结果
     */
    @Override
    public int updateOOceanArea(OOceanArea oOceanArea)
    {
        SysUser sysUser = ShiroUtils.getSysUser();
        oOceanArea.setUpdateName(sysUser.getUserName());
        oOceanArea.setUpdateBy(sysUser.getLoginName());
        oOceanArea.setUpdateDate(new Date());
        return oOceanAreaMapper.updateOOceanArea(oOceanArea);
    }

    /**
     * 批量删除海区维护
     *
     * @param ids 需要删除的海区维护主键
     * @return 结果
     */
    @Override
    public int deleteOOceanAreaByIds(String ids)
    {
        return oOceanAreaMapper.deleteOOceanAreaByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除海区维护信息
     *
     * @param id 海区维护主键
     * @return 结果
     */
    @Override
    public int deleteOOceanAreaById(String id)
    {
        return oOceanAreaMapper.deleteOOceanAreaById(id);
    }

    /**
     * 获取所有海区的名称和编码
     * @return
     */
    @Override
    public Map<String, List> getNameAndCodeList() {
        Map<String, List> result = new HashMap<>();
        List<String> names = new ArrayList<>();
        List<String> codes = new ArrayList<>();
        List<OOceanArea> list = oOceanAreaMapper.selectOOceanAreaList(new OOceanArea());
        for (OOceanArea area : list) {
            names.add(area.getAreaName());
            codes.add(area.getAreaCode());
        }
        result.put("names",names);result.put("codes",codes);
        return result;
    }

    @Override
    public List<OOceanArea> getAllOceanArea() {
        return oOceanAreaMapper.getAllOceanArea();
    }
}
